/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package org.vale.entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Gabriel Bran gbran.u@gmail.com
 */
@Entity
@Table(name = "form_template")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "FormTemplate.findAll", query = "SELECT f FROM FormTemplate f"),
    @NamedQuery(name = "FormTemplate.findByIdForm", query = "SELECT f FROM FormTemplate f WHERE f.idForm = :idForm"),
    @NamedQuery(name = "FormTemplate.findByName", query = "SELECT f FROM FormTemplate f WHERE f.name = :name"),
    @NamedQuery(name = "FormTemplate.findByDescription", query = "SELECT f FROM FormTemplate f WHERE f.description = :description")})
public class FormTemplate implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id_form")
    private Integer idForm;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "name")
    private String name;
    @Size(max = 100)
    @Column(name = "description")
    private String description;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idForm")
    private List<FormQuestion> formQuestionList;

    public FormTemplate() {
    }

    public FormTemplate(Integer idForm) {
        this.idForm = idForm;
    }

    public FormTemplate(Integer idForm, String name) {
        this.idForm = idForm;
        this.name = name;
    }

    public Integer getIdForm() {
        return idForm;
    }

    public void setIdForm(Integer idForm) {
        this.idForm = idForm;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @XmlTransient
    public List<FormQuestion> getFormQuestionList() {
        return formQuestionList;
    }

    public void setFormQuestionList(List<FormQuestion> formQuestionList) {
        this.formQuestionList = formQuestionList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idForm != null ? idForm.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof FormTemplate)) {
            return false;
        }
        FormTemplate other = (FormTemplate) object;
        if ((this.idForm == null && other.idForm != null) || (this.idForm != null && !this.idForm.equals(other.idForm))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.vale.entity.FormTemplate[ idForm=" + idForm + " ]";
    }
    
}
